package test.svncleaner;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class SVNCleaner
{
	private final String SVN_FOLDER_NAME = ".svn";

	private final File SRC_ROOT = new File("E:/Java/eclipse/workspace/Spring_1500_AOP_Annotation_Maven - Copy");

	private BufferedReader bf;
	private String line;

	public static void main(String[] args)
	{
		try
		{
			new SVNCleaner().launch();
		}
		catch (FileNotFoundException e)
		{
			e.printStackTrace();
		}
		catch (NullPointerException e)
		{
			e.printStackTrace();
		}
		catch (IOException e)
		{
			e.printStackTrace();
		}
	}

	private void launch() throws FileNotFoundException, NullPointerException,
			IOException
	{
		cleanThisPath(SRC_ROOT);
	}

	private void cleanThisPath(File path) throws FileNotFoundException,
			NullPointerException, IOException
	{
		if (path.isDirectory() && path.toString().endsWith(SVN_FOLDER_NAME))
		{
			deleteFolder(path);
			return;
		}
		if (path.isDirectory())
		{
			File[] files = path.listFiles();
			for (int i = 0; i < files.length; i++)
			{
				cleanThisPath(files[i]);
			}
		}
	}

	private void deleteFolder(File path)
	{
		if(path.isFile()){
			path.delete();
			return;
		}
		
		if(path.isDirectory()){
			File[] files = path.listFiles();
			for (int i = 0; i < files.length; i++)
			{
				deleteFolder(files[i]);
			}
			path.delete();
		}
	}
}
